<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >

      <el-form-item label="企业名称" prop="corpName">
        <el-input
          v-model="queryParams.corpName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一信用代码" prop="corpCredit" label-width="200">
        <el-input
          v-model="queryParams.corpCredit"
          placeholder="请输入统一信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业联系人" prop="contactPerson" label-width="200">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入企业联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业联系方式" prop="contactPhone" label-width="200">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入企业联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="走访时间" prop="visitDate">
        <el-input
          v-model="queryParams.visitDate"
          placeholder="请输入走访时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="走访情况" prop="visitRemark">
        <el-input
          v-model="queryParams.visitRemark"
          placeholder="请输入走访情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="走访状态" prop="visitStatus" label-width="300">
        <el-select
          clearable
          v-model="queryParams.visitStatus"
          placeholder="请选择走访状态"
        >
          <el-option
            v-for="item in visitStatusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="问卷状态"
        prop="questionnaireStatus"
        label-width="300"
      >
        <el-select
          clearable
          v-model="queryParams.questionnaireStatus"
          placeholder="请选择问卷状态"
        >
          <el-option
            v-for="item in questionnaireStatusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="授信金额" prop="creditAmount">
        <el-input
          v-model="queryParams.creditAmount"
          placeholder="请输入授信金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用信金额" prop="useAmount">
        <el-input
          v-model="queryParams.useAmount"
          placeholder="请输入用信金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送批次号" prop="pushId">
        <el-input
          v-model="queryParams.pushId"
          placeholder="请输入推送批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业简称" prop="shortName">
        <el-input
          v-model="queryParams.shortName"
          placeholder="请输入企业简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业经营地址是否与注册地址一致" prop="addressIsSyn">
        <el-input
          v-model="queryParams.addressIsSyn"
          placeholder="请输入企业经营地址是否与注册地址一致"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="距离" prop="distance">
        <el-input
          v-model="queryParams.distance"
          placeholder="请输入距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已填写问卷 1是；0否" prop="qrcode">
        <el-input
          v-model="queryParams.qrcode"
          placeholder="请输入是否已填写问卷 1是；0否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除用户" prop="deleteUser">
        <el-input
          v-model="queryParams.deleteUser"
          placeholder="请输入删除用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入删除标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['visitcorp:RESULTS:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visitcorp:RESULTS:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visitcorp:RESULTS:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['visitcorp:RESULTS:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="RESULTSList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column
        label="MINI_BANK_VIST_CORP表ID"
        align="center"
        prop="visitCorpId"
      /> -->
      <!-- <el-table-column label="用户id" align="center" prop="userId" /> -->
      <el-table-column
        label="企业名称"
        align="center"
        prop="corpName"
        width="300"
      />
      <el-table-column
        label="统一信用代码"
        align="center"
        prop="corpCredit"
        width="200"
      />
      <el-table-column label="企业联系人" align="center" prop="contactPerson"/>
      <el-table-column
        label="企业联系方式"
        align="center"
        prop="contactPhone"
      />
      <el-table-column label="走访时间" align="center" prop="visitDate"/>
      <el-table-column label="走访情况" align="center" prop="visitRemark"/>
      <el-table-column label="走访状态" align="center" prop="visitStatus"/>
      <el-table-column
        label="问卷状态"
        align="center"
        prop="questionnaireStatus"
      />
      <!-- <el-table-column
        label="走访图片地址"
        align="center"
        prop="visitPictureUrl"
      /> -->
      <el-table-column label="问卷答案" align="center" prop="answer"/>
      <el-table-column label="授信金额" align="center" prop="creditAmount"/>
      <el-table-column label="用信金额" align="center" prop="useAmount"/>
      <!-- <el-table-column label="推送批次号" align="center" prop="pushId" /> -->
      <!-- <el-table-column label="企业简称" align="center" prop="shortName" /> -->
      <!-- <el-table-column label="打卡位置" align="center" prop="corpLocation" /> -->
      <!-- <el-table-column
        label="企业经营地址是否与注册地址一致"
        align="center"
        prop="addressIsSyn"
      /> -->
      <!-- <el-table-column
        label="地址是否一致说明"
        align="center"
        prop="isSynComment"
      /> -->
      <!-- <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="距离" align="center" prop="distance" />
      <el-table-column label="企业实际地址" align="center" prop="addr" /> -->
      <!-- <el-table-column
        label="是否已填写问卷 1是；0否"
        align="center"
        prop="qrcode"
      /> -->
      <!-- <el-table-column label="职务" align="center" prop="position" /> -->
      <!-- <el-table-column label="删除用户" align="center" prop="deleteUser" /> -->
      <!-- <el-table-column label="删除标识" align="center" prop="isDelete" /> -->
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.contactPhone ? false : true"
            size="mini"
            type="text"
            @click="checkzf(scope.row)"
            v-hasPermi="['visitcorp:RESULTS:edit']"
            class="operate_button"
          >查看走访问卷
          </el-button
          >
          <el-button
            size="mini"
            type="text"
            :disabled="scope.row.qyQustion ? false : true"
            @click="checkqy(scope.row)"
            class="operate_button"
            v-hasPermi="['visitcorp:RESULTS:edit']"
          >查看企业问卷
          </el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            class="operate_button"
            v-hasPermi="['visitcorp:RESULTS:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            class="operate_button"
            v-hasPermi="['visitcorp:RESULTS:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改小程序_企业走访成果（银行自己上传功能）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="MINI_BANK_VIST_CORP表ID" prop="visitCorpId">
          <el-input
            v-model="form.visitCorpId"
            placeholder="请输入MINI_BANK_VIST_CORP表ID"
          />
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id"/>
        </el-form-item>
        <el-form-item label="企业名称" prop="corpName">
          <el-input v-model="form.corpName" placeholder="请输入企业名称"/>
        </el-form-item>
        <el-form-item label="统一信用代码" prop="corpCredit">
          <el-input
            v-model="form.corpCredit"
            placeholder="请输入统一信用代码"
          />
        </el-form-item>
        <el-form-item label="企业联系人" prop="contactPerson">
          <el-input
            v-model="form.contactPerson"
            placeholder="请输入企业联系人"
          />
        </el-form-item>
        <el-form-item label="企业联系方式" prop="contactPhone">
          <el-input
            v-model="form.contactPhone"
            placeholder="请输入企业联系方式"
          />
        </el-form-item>
        <el-form-item label="走访时间" prop="visitDate">
          <el-input v-model="form.visitDate" placeholder="请输入走访时间"/>
        </el-form-item>
        <el-form-item label="走访情况" prop="visitRemark">
          <el-input
            v-model="form.visitRemark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="走访图片地址" prop="visitPictureUrl">
          <el-input
            v-model="form.visitPictureUrl"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="问卷答案" prop="answer">
          <el-input
            v-model="form.answer"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="授信金额" prop="creditAmount">
          <el-input v-model="form.creditAmount" placeholder="请输入授信金额"/>
        </el-form-item>
        <el-form-item label="用信金额" prop="useAmount">
          <el-input v-model="form.useAmount" placeholder="请输入用信金额"/>
        </el-form-item>
        <el-form-item label="推送批次号" prop="pushId">
          <el-input v-model="form.pushId" placeholder="请输入推送批次号"/>
        </el-form-item>
        <el-form-item label="企业简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入企业简称"/>
        </el-form-item>
        <el-form-item label="打卡位置" prop="corpLocation">
          <el-input
            v-model="form.corpLocation"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item
          label="企业经营地址是否与注册地址一致"
          prop="addressIsSyn"
        >
          <el-input
            v-model="form.addressIsSyn"
            placeholder="请输入企业经营地址是否与注册地址一致"
          />
        </el-form-item>
        <el-form-item label="地址是否一致说明" prop="isSynComment">
          <el-input
            v-model="form.isSynComment"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度"/>
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度"/>
        </el-form-item>
        <el-form-item label="距离" prop="distance">
          <el-input v-model="form.distance" placeholder="请输入距离"/>
        </el-form-item>
        <el-form-item label="企业实际地址" prop="addr">
          <el-input
            v-model="form.addr"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="是否已填写问卷 1是；0否" prop="qrcode">
          <el-input
            v-model="form.qrcode"
            placeholder="请输入是否已填写问卷 1是；0否"
          />
        </el-form-item>
        <el-form-item label="职务" prop="position">
          <el-input v-model="form.position" placeholder="请输入职务"/>
        </el-form-item>
        <el-form-item label="删除用户" prop="deleteUser">
          <el-input v-model="form.deleteUser" placeholder="请输入删除用户"/>
        </el-form-item>
        <el-form-item label="删除标识" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入删除标识"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <zfquestionnaireDetail ref="zfquestionnaireDetail"></zfquestionnaireDetail>
    <qyquestionnaireDetail ref="qyquestionnaireDetail"></qyquestionnaireDetail>
  </div>
</template>

<script>
import {addRESULTS, delRESULTS, getRESULTS, listRESULTS, updateRESULTS,} from "@/api/visitcorp/RESULTS";
import qyquestionnaireDetail from "../../../components/qyquestionnaireDetail.vue";
import zfquestionnaireDetail from "../../../components/zfquestionnaireDetail.vue";

export default {
  name: "RESULTS",
  components: {
    qyquestionnaireDetail,
    zfquestionnaireDetail,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 小程序_企业走访成果（银行自己上传功能）表格数据
      RESULTSList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        visitCorpId: null,
        userId: null,
        corpName: null,
        corpCredit: null,
        contactPerson: null,
        contactPhone: null,
        visitDate: null,
        visitRemark: null,
        visitStatus: null,
        questionnaireStatus: null,
        visitPictureUrl: null,
        answer: null,
        creditAmount: null,
        useAmount: null,
        pushId: null,
        shortName: null,
        corpLocation: null,
        addressIsSyn: null,
        isSynComment: null,
        longitude: null,
        latitude: null,
        distance: null,
        addr: null,
        qrcode: null,
        position: null,
        deleteUser: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      questionnaireStatusList: [
        {
          value: "问卷已进行",
          label: "问卷已进行",
        },
        {
          value: "问卷未进行",
          label: "问卷未进行",
        },
      ],
      visitStatusList: [
        {
          value: "已走访无需求",
          label: "已走访无需求",
        },
        {
          value: "已走访有意向",
          label: "已走访有意向",
        },
        {
          value: "已走访且授信",
          label: "已走访且授信",
        },
        {
          value: "有意向末准入",
          label: "有意向末准入",
        },
        {
          value: "已授信且用信",
          label: "已授信且用信",
        },
        {
          value: "未走访",
          label: "未走访",
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询小程序_企业走访成果（银行自己上传功能）列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams, "查询条件");
      listRESULTS(this.queryParams).then((response) => {
        this.RESULTSList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        visitCorpId: null,
        userId: null,
        corpName: null,
        corpCredit: null,
        contactPerson: null,
        contactPhone: null,
        visitDate: null,
        visitRemark: null,
        visitStatus: null,
        questionnaireStatus: null,
        visitPictureUrl: null,
        answer: null,
        creditAmount: null,
        useAmount: null,
        pushId: null,
        shortName: null,
        corpLocation: null,
        addressIsSyn: null,
        isSynComment: null,
        longitude: null,
        latitude: null,
        distance: null,
        addr: null,
        qrcode: null,
        position: null,
        deleteUser: null,
        isDelete: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加小程序_企业走访成果（银行自己上传功能）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getRESULTS(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改小程序_企业走访成果（银行自己上传功能）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateRESULTS(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRESULTS(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 查看走访问卷
    checkzf(val) {
      // this.$refs.qyquestionnaireDetail.url = `http://192.168.1.44:8879/#/questionnaire/interview?corpName=${val.corpName}&shortName=${val.shortName}&corpCredit=${val.corpCredit}&userId=${val.userId}&myId=${val.id}`;
      // this.$nextTick(() => {
      //   this.$refs.qyquestionnaireDetail.DialogVisible = true;
      // });
      this.$refs.zfquestionnaireDetail.isShow(val);
      // this.$refs.zfquestionnaireDetail.item = val
      // this.$nextTick(() => {
      //   this.$refs.zfquestionnaireDetail.DialogVisible = true;
      // });
    },
    // 查看企业问卷
    checkqy(val) {
      console.log(JSON.parse(val.qyQustion), '查看内容')
      this.$refs.qyquestionnaireDetail.isShow(val);
      // 嵌套版本
      // this.$refs.qyquestionnaireDetail.url = `http://192.168.1.44:8879/#/questionnaire/interview?corpCredit=${val.corpCredit}&corpName=${val.corpName}&shortName=${val.shortName}&type=1&userId=${val.userId}&myId=${val.id}`;
      // this.$nextTick(() => {
      //   this.$refs.qyquestionnaireDetail.DialogVisible = true;
      // });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm(
          '是否确认删除小程序_企业走访成果（银行自己上传功能）编号为"' +
          ids +
          '"的数据项？'
        )
        .then(function () {
          return delRESULTS(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "visitcorp/RESULTS/export",
        {
          ...this.queryParams,
        },
        `RESULTS_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.operate_button {
  margin-left: 0 !important;
}

::v-deep .el-form-item__label {
  width: 150px;
}
</style>
